<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>fnmatch</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_005_149">&nbsp;</a>NAME</h4><blockquote>
fnmatch - match a filename or a pathname
</blockquote><h4><a name = "tag_000_005_150">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="fnmatch.h.html">fnmatch.h</a>&gt;

int fnmatch(const char *<i>pattern</i>, const char *<i>string</i>, int <i>flags</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_005_151">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>fnmatch()</i>
function matches patterns as described in the <b>XCU</b> specification, <b>Section 2.13.1</b>, <b>Patterns Matching a Single Character</b>, and <b>Section 2.13.2</b>, <b>Patterns Matching Multiple Characters</b>.
It checks the string specified by the
<i>string</i>
argument to see if it matches the pattern specified by the
<i>pattern</i>
argument.
<p>
The
<i>flags</i>
argument modifies the interpretation of
<i>pattern</i>
and
<i>string</i>.
It is the bitwise inclusive OR of zero or more of the flags defined in the
header
<i><a href="fnmatch.h.html">&lt;fnmatch.h&gt;</a></i>.
If the FNM_PATHNAME flag is set in
<i>flags</i>,
then a slash character in
<i>string</i>
will be explicitly matched by a slash in
<i>pattern</i>;
it will not be matched by either the asterisk or question-mark special
characters, nor by a bracket expression.
If the FNM_PATHNAME flag is not set,
the slash character is treated as an
ordinary character.
<p>
If FNM_NOESCAPE is not set in
<i>flags</i>,
a backslash character (\) in
<i>pattern</i>
followed by any other character will match that second character in
<i>string</i>.
In particular, \\ will match a backslash in
<i>string</i>.
If FNM_NOESCAPE is set, a backslash character will
be treated as an ordinary character.
<p>
If FNM_PERIOD is set in
<i>flags</i>,
then a leading period in
<i>string</i>
will match a period in
<i>pattern</i>;
as described by rule 2 in the <b>XCU</b> specification, <b>Section 2.13.3</b>, <b>Patterns Used for Filename Expansion</b>
where the location of &quot;leading&quot; is indicated by the value of FNM_PATHNAME:
<ul>
<p>
<li>
If FNM_PATHNAME is set, a period is
&quot;leading&quot; if it is the first character in
<i>string</i>
or if it immediately follows a slash.
<p>
<li>
If FNM_PATHNAME is not set, a period is
&quot;leading&quot; only if it is the first character of
<i>string</i>.
<p>
</ul>
<p>
If FNM_PERIOD is not set, then no special restrictions are
placed on matching a period.
</blockquote><h4><a name = "tag_000_005_152">&nbsp;</a>RETURN VALUE</h4><blockquote>
If
<i>string</i>
matches the pattern specified by
<i>pattern</i>,
then
<i>fnmatch()</i>
returns 0.
If there is no match,
<i>fnmatch()</i>
returns FNM_NOMATCH, which is defined in the header
<i><a href="fnmatch.h.html">&lt;fnmatch.h&gt;</a></i>.
If an error occurs,
<i>fnmatch()</i>
returns another non-zero value.
</blockquote><h4><a name = "tag_000_005_153">&nbsp;</a>ERRORS</h4><blockquote>
No errors are defined.
<br>
</blockquote><h4><a name = "tag_000_005_154">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_005_155">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
The
<i>fnmatch()</i>
function has two major uses.
It could be used by an application or utility that needs to read a
directory and apply a pattern against each entry.
The
<i><a href="../xcu/find.html">find</a></i>
utility is an example of this.
It can also be used by the
<i><a href="../xcu/pax.html">pax</a></i>
utility to process its
<i>pattern</i>
operands, or by applications that need to match strings in a
similar manner.
<p>
The name
<i>fnmatch()</i>
is intended to imply
<i>filename</i>
match, rather than
<i>pathname</i>
match.
The default action of this function is to match filenames, rather than
pathnames, since it gives no special significance to the slash
character.
With the FNM_PATHNAME flag,
<i>fnmatch()</i>
does match pathnames, but without tilde expansion, parameter expansion, or
special treatment for period at the beginning of a filename.
</blockquote><h4><a name = "tag_000_005_156">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_005_157">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="glob.html">glob()</a></i>,
<i><a href="wordexp.html">wordexp()</a></i>,
<i><a href="fnmatch.h.html">&lt;fnmatch.h&gt;</a></i>,
the <b>XCU</b> specification.
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from the ISO POSIX-2 standard.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

